package com.hqyj.controller;

import com.hqyj.pojo.DataMessage;
import com.hqyj.pojo.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/login")
public class LoginController {
    //定义访问login页面
    @RequestMapping("/loginPage")
    public String login(){
        return "login";
    }
    //定义ajax登录请求
    @RequestMapping("/loginAjax")
    @ResponseBody
    public DataMessage loginAjax(UserInfo userInfo){
        //假设返回服务层的数据模型
        DataMessage data = new DataMessage();
        if (userInfo.getUserName().equals("admin")&&userInfo.getUserPwd().equals("123")) {
            System.out.println("登陆成功");
            data.setSuccess(true);
            data.setInfo("登陆成功");
        }else {
            System.out.println("登陆失败");
            data.setSuccess(false);
            data.setInfo("登陆失败");
        }
        return data;
    }
    @RequestMapping("/loginAjaxTwo")
    @ResponseBody
    public DataMessage loginAjaxTwo(@RequestBody UserInfo userInfo){
        //假设返回服务层的数据模型
        DataMessage data = new DataMessage();
        if (userInfo.getUserName().equals("admin")&&userInfo.getUserPwd().equals("123")) {
            System.out.println("登陆成功");
            data.setSuccess(true);
            data.setInfo("登陆成功");
        }else {
            System.out.println("登陆失败");
            data.setSuccess(false);
            data.setInfo("登陆失败");
        }
        return data;
    }
}
